/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} val
 * @return {TreeNode}
 */
 var searchBST = function(root, val) {
     if(!root){
         return null;
     }
     if(val>root.val){
        return searchBST(root.right,val);
    }
    else if(val<root.val){
        return searchBST(root.left,val);
    }
    else{
        return root;
    }
}
 var searchBST = function(root, val) {
     let res;
     function dfs(root){
         if(!root){
             res=null;
             return ;
         }
         if(val>root.val){
             dfs(root.right);
         }
         else if(val<root.val){
             dfs(root.left);
         }
         else{
             res=root;
             return ;
         }
     }
     dfs(root);
     return res;
};